//
//  AddressHelper.m
//  Lovely Food
//
//  Created by 李经纬 on 15/12/8.
//  Copyright © 2015年 李经纬. All rights reserved.
//

#import "AddressHelper.h"

@interface AddressHelper ()

@property (nonatomic, strong) NSMutableArray *provinceArray;

@property (nonatomic, strong) NSMutableArray *cityArray;

@property (nonatomic, strong) NSMutableArray *countArray;

@end
@implementation AddressHelper

// 懒加载
- (NSMutableArray *)provinceArray
{
    if (_provinceArray == nil) {
        self.provinceArray = [NSMutableArray arrayWithCapacity:10];
    }
    return _provinceArray;
}

- (NSMutableArray *)cityArray
{
    if (_cityArray == nil) {
        self.cityArray = [NSMutableArray arrayWithCapacity:10];
    }
    return _cityArray;
}

- (NSMutableArray *)countArray
{
    if (_countArray == nil) {
        self.countArray = [NSMutableArray arrayWithCapacity:10];
    }
    return _countArray;
}

//提取城市的plist
- (void)makeValue
{
    
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"area" ofType:@"plist"];
    NSMutableDictionary *dataDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
//    NSLog(@"%@",dataDictionary);
    for (int i = 0; i < 34; i++) {
        
        NSMutableDictionary *dict = dataDictionary[[NSString stringWithFormat:@"%d", i]];
        NSString *str = [dict allKeys][0];
        [self.provinceArray addObject:str];
        NSMutableDictionary *dictVlues = dict[str];
        NSMutableArray *array = [NSMutableArray arrayWithCapacity:10];
        for (NSString *key in dictVlues) {
            NSString *cityStr = [[dictVlues objectForKey:key] allKeys][0];
            if ([cityStr isEqualToString:str]) {
                
                array = [dictVlues objectForKey:key][cityStr];
//                NSLog(@"%@~~~~~~~~~~~~",array);
//                NSLog(@"%@==== %@", cityStr , str);
                
            } else {
                
                [array addObject:cityStr];
            }
            
        }
        [self.cityArray addObject:array];
        
    }
}

//返回省份
- (NSMutableArray *)returnProvince
{
    [self makeValue];
    return self.provinceArray;
}

// 返回城市
- (NSMutableArray *)returnCity
{
    [self makeValue];
    return self.cityArray;
}


//返回县
- (NSMutableArray *)returnCounty
{
    [self makeValue];
    return self.countArray;
}

@end
